import React, { useState, createContext,useContext } from 'react';
// import SubCountVal from './SubCountVal'
function CreateContext() {
  const [num, handChange] = useState(0) 
  const CountVal = createContext()
  function SubCountVal(){
    let news = useContext(CountVal)
    return (<div>子组件： {news}</div>)
  }
  return (
    <div>
        <h2>react Hooks基本用法</h2><br />
        <h3>你点击了 {num} 次！</h3>
        <button onClick={()=>{handChange(num+1)}}>点击加1</button><br /><br />
        <hr />
        <CountVal.Provider value={num}>
          <SubCountVal />
          {/* <SubCountVal countVal={CountVal} /> */}
        </CountVal.Provider>
      </div>
  )
}
export default CreateContext


